package com.beerbase;

import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;


public class BeerBase extends Activity {
	
	private List<String> modelBeers = new ArrayList<String>();
	private List<String> modelBreweries = new ArrayList<String>();
	private List<String> modelTypes = new ArrayList<String>();
	
	private ArrayAdapter<String> adapterBeers = null;
	private ArrayAdapter<String> adapterBreweries = null;
	private ArrayAdapter<String> adapterTypes = null;
	//private ArrayAdapter<String> adapter = null;
	
	private Database db = null;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);  

        db = new Database(this);
        
        //adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, model);
        adapterBeers = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, modelBeers);
        adapterBreweries = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, modelBreweries); // <- huomaa spinner!
        adapterTypes = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, modelTypes); 
        
		db.fillBeers(adapterBeers);
		db.fillBreweries(adapterBreweries);
		db.fillTypes(adapterTypes);
    }
	 
    public void switchToBrowseBeers(View v) {
    	setContentView(R.layout.browsebeer);
   
    	//adapter.clear();
    	//db.fillBeers(adapter);
    	
    	ListView list=(ListView)findViewById(R.id.ListViewBeers);
		list.setAdapter(adapterBeers);
			
		/*adapter.add("Guinness");
		adapter.add("Eggenberg");
		adapter.add("Very Bad Elf");*/	   
  	}
    
    public void switchToAddNew(View v){
    	setContentView(R.layout.beer);
    	
    	Spinner spinner = (Spinner)findViewById(R.id.SpinnerType);
    	spinner.setAdapter(adapterBreweries);
    	
    }
    
    public void switchToMain(View v){
    	setContentView(R.layout.main);
    	
    }
}
